package com.server;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class OutputStreamHandler extends Thread {
	private OutputStream	os;
	private Socket			s;
	private Monitor			m;
	private int				clientId;

	public OutputStreamHandler(Socket s, Monitor m, int clientId)
	{
		this.m = m;
		this.s = s;
		this.clientId = clientId;
		try
		{
			os = s.getOutputStream();
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public void run()
	{
		while (true)
		{
			try
			{
				byte[] b = m.getOutgoing(clientId);
				os.write(b);
			} catch (IOException e)
			{
				System.out.println("Ended connection to client nr. " + clientId + " @ " + s.getInetAddress());
				break;
			}
		}
	}

}
